From 71acbce63acf3f6181959f11f0840ba01be3b9d2 Mon Sep 17 00:00:00 2001 From: "sos22@douglas.cl.cam.ac.uk" Date: Thu, 9 Jun 2005 10:54:32 +0000 Subject: [PATCH] bitkeeper revision 1.1696 (42a81fe89VPLawDxu2WTiKLZH-Br3Q) Make sure the grant table stuff uses locked cmpxchg instructions even when compiled !CONFIG_SMP. Signed-off-by: Steven Smith --- .../arch/xen/kernel/gnttab.c | 5 ++- .../include/asm-xen/asm-i386/synch_bitops.h | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/linux-2.6.11-xen-sparse/arch/xen/kernel/gnttab.c b/linux-2.6.11-xen-sparse/arch/xen/kernel/gnttab.c index 8fe43247ac..0106a6fea0 100644 --- a/linux-2.6.11-xen-sparse/arch/xen/kernel/gnttab.c +++ b/linux-2.6.11-xen-sparse/arch/xen/kernel/gnttab.c @@ -19,6 +19,7 @@ #include #include #include +#include #if 1 #define ASSERT(_p) \ @@ -125,7 +126,7 @@ gnttab_end_foreign_access( grant_ref_t ref, int readonly ) if ( (flags = nflags) & (GTF_reading|GTF_writing) ) printk(KERN_ALERT "WARNING: g.e. still in use!\n"); } - while ( (nflags = cmpxchg(&shared[ref].flags, flags, 0)) != flags ); + while ( (nflags = synch_cmpxchg(&shared[ref].flags, flags, 0)) != flags ); put_free_entry(ref); } @@ -172,7 +173,7 @@ gnttab_end_foreign_transfer( * Otherwise invalidate the grant entry against future use. */ if ( likely(flags != GTF_accept_transfer) || - (cmpxchg(&shared[ref].flags, flags, 0) != GTF_accept_transfer) ) + (synch_cmpxchg(&shared[ref].flags, flags, 0) != GTF_accept_transfer) ) while ( unlikely((frame = shared[ref].frame) == 0) ) cpu_relax(); diff --git a/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/synch_bitops.h b/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/synch_bitops.h index 8093de0ac9..6af3ad2857 100644 --- a/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/synch_bitops.h +++ b/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/synch_bitops.h @@ -60,6 +60,46 @@ static __inline__ int synch_test_and_change_bit(int nr, volatile void * addr) return oldbit; } +struct __synch_xchg_dummy { unsigned long a[100]; }; +#define __synch_xg(x) ((struct __synch_xchg_dummy *)(x)) + +#define synch_cmpxchg(ptr, old, new) \ +((__typeof__(*(ptr)))__synch_cmpxchg((ptr),\ + (unsigned long)(old), \ + (unsigned long)(new), \ + sizeof(*(ptr)))) + +static inline unsigned long __synch_cmpxchg(volatile void *ptr, + unsigned long old, + unsigned long new, int size) +{ + unsigned long prev; + switch (size) { + case 1: + __asm__ __volatile__("lock; cmpxchgb %b1,%2" + : "=a"(prev) + : "q"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; + case 2: + __asm__ __volatile__("lock; cmpxchgw %w1,%2" + : "=a"(prev) + : "q"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; + case 4: + __asm__ __volatile__("lock; cmpxchgl %1,%2" + : "=a"(prev) + : "q"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; + } + return old; +} + static __inline__ int synch_const_test_bit(int nr, const volatile void * addr) { return ((1UL << (nr & 31)) & -- 2.30.2